/**
* Copyright (c) 2004-2005 Luciano Xumerle. All rights reserved.
*
* This file is part of gephinfo.
*
* gephinfo is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
 * COMPILE:
 * javac -classpath jenoware.jar HWE.java
 *
 * EXECUTE:
 * java -classpath jenoware.jar HWE file.csv ...
 *
 * The program opens a CSV file and prints some descriptive statistics
 * and tests for Hardy-Weinberg equilibrium.
 *
 */

// import jenoware packages
import it.ciano.jenoware.*;

public class HWEexample {
    public HWEexample() {
    }

    public static void main ( String[] args )
    throws java.io.IOException {
        // the Pedigree object
        Pedigree ped = new Pedigree();
        // add all the CSV files to the Pedigree
        for ( int i = 0; i < args.length; i++ )
            if ( args[ i ].indexOf ( ".csv", 0 ) > 0 )
                toPedigree.importCSV ( ped, args[ i ], ";" );
            else if ( args[ i ].indexOf ( ".ped", 0 ) > 0 )
                GetLINKAGE.addPEDfile ( ped, args[ i ], false );

        // print markers statistics
        String[] markers = ped.getMarkersList();
        if ( markers != null ) {
            System.out.println ( "Printing Genotype Statistics:\n" );
            for ( int i = 0; i < markers.length; i++ ) {
                System.out.println ( ped.pedCheck ( markers[ i ] ) );
                MarkerFreq ll = new MarkerFreq ( ped, markers[ i ] );
                // print the descriptive statistics
                System.out.println ( ll );
                // print test for Hardy-Weinberg equilibrium
                // with simulation (get 10000 simulated chi-square)
                System.out.println ( ll.getHWE ( 0, true ) );
            }
        }
    } // end main

} //end class

